<?php

require 'js_node.class.php';
require 'js_root_node.class.php';
require 'js_for_node.class.php';
require 'js_if_node.class.php';
require 'js_condition_node.class.php';
require 'js_assignment_node.class.php';
require 'js_add_node.class.php';
require 'js_multiply_node.class.php';
require 'js_divide_node.class.php';
require 'js_increment_node.class.php';
require 'js_decrement_node.class.php';
require 'js_equality_node.class.php';
require 'js_less_than_node.class.php';
require 'js_greater_than_node.class.php';
require 'js_var_node.class.php';
require 'js_array_node.class.php';
require 'js_number_node.class.php';
require 'js_string_node.class.php';
require 'js_remainder_node.class.php';

class JS_AST {

	protected $root;
	
	public function __construct() {
		$this->root = new JS_RootNode(0);
	}
	
	public function &getRoot() {
		return $this->root;
	}
	
	public function setRoot(Node &$root=null) {
		$this->root = $root;
	}
	
	public function __toString() {
		return $this->_toString($this->root);
	}
	
	private function _toString(Node &$node=null) {
		if (!$node) {
			_d($node);
			return '';
		}
		
		if ($len = $node->getNumChildren()) {
			_d($node->__toString());
			A$i = 0; $js = array();
			while ($i < $len) {
				$js[] = $this->_toString($node->getChild($i));
				++$i;
			}
			return implode(' ', $js);
		}
		else {
			return $node->__toString();
		}
	}
	
}

?>